home *** CD-ROM | disk | FTP | other *** search
- package asp.wizard;
-
- import asp.netobjects.nfx.util.ExceptionHandler;
- import asp.netobjects.nfx.util.ExternalError;
- import asp.netobjects.nfx.util.InternalError;
- import asp.netobjects.nfx.wizard.Wizard;
- import asp.netobjects.nfx.wizard.WizardPage;
- import asp.netobjects.nfx.wizard.WizardPageView;
- import asp.util.ResourceUtil;
- import asp.wizard.def.DefAbstract;
- import asp.wizard.def.DefCollection;
- import asp.wizard.def.DefConnection;
- import asp.wizard.def.DefList;
- import asp.wizard.def.DefPage;
- import asp.wizard.def.DefQuery;
- import asp.wizard.util.UiUtil;
- import com.sun.java.swing.DefaultListModel;
- import com.sun.java.swing.ImageIcon;
- import com.sun.java.swing.table.DefaultTableModel;
- import com.sun.java.swing.table.TableModel;
- import java.lang.reflect.Array;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.text.MessageFormat;
- import java.util.Vector;
-
- public class WizardModelDbList3 extends WizardModelAbstract {
- private static final String ERR_TOOMANY_KEYFIELDS = "msg.error.toomanykeyfields";
- private static final String ERR_MISSING_VALUE_ON_LINE = "msg.error.missingvalueonline";
- private static final String OPT_KEYFIELD_TYPE = "option.kfldtype";
- private static final int MSDBLIST_MAX_KEYFIELDS = 10;
- private DefList _defList;
- private int _linkOption = 1001;
- // $FF: synthetic field
- static Class class$java$lang$String;
- // $FF: synthetic field
- static Class class$asp$wizard$WVPanelDbListLink;
- // $FF: synthetic field
- static Class class$asp$nfx$MSDBList$MSDBList;
- // $FF: synthetic field
- static Class class$java$lang$Object;
- // $FF: synthetic field
- static Class class$asp$wizard$WizardModelDbConnection;
- // $FF: synthetic field
- static Class class$asp$wizard$WizardModelDbQuery;
- // $FF: synthetic field
- static Class class$asp$wizard$WizardModelDbDetail;
-
- public void commit() throws InternalError, ExternalError {
- WizardViewDbList3 view = (WizardViewDbList3)((WizardPage)this).getView();
- this._defList.setHyperlinkField(view.getHyperlinkField());
- this._linkOption = view.getLinkOption();
- TableModel tm = view.getFieldSpecTable().getModel();
-
- for(int i = 0; i < tm.getRowCount(); ++i) {
- if (tm.getValueAt(i, 2).toString().compareTo("") == 0) {
- tm.setValueAt(tm.getValueAt(i, 0), i, 2);
- }
- }
-
- this._defList.setKeyFieldNames((String[])UiUtil.getColumnArrayFromTableModel(0, tm, class$java$lang$String != null ? class$java$lang$String : (class$java$lang$String = class$("java.lang.String"))));
- Vector dataTypes = this.getDataTypes();
- this._defList.setKeyFieldDataTypes(getColumnArrayFromTableModelTranslate(1, tm, Integer.TYPE, dataTypes));
- this._defList.setKeyFieldLabels((String[])UiUtil.getColumnArrayFromTableModel(2, tm, class$java$lang$String != null ? class$java$lang$String : (class$java$lang$String = class$("java.lang.String"))));
- }
-
- public void loadValues() {
- WizardViewDbList3 view = (WizardViewDbList3)((WizardPage)this).getView();
- DefaultTableModel tm = (DefaultTableModel)view.getFieldSpecTable().getModel();
- view.setLinkOption(this._linkOption);
- view.updateFieldSpecTableColumnsVisibility();
- tm.setNumRows(0);
- UiUtil.setTableModelFromColumnArray(0, tm, this._defList.getKeyFieldNames());
- UiUtil.setTableModelFromColumnArray(2, tm, this._defList.getKeyFieldLabels());
- Vector dataTypes = this.getDataTypes();
- setTableModelFromColumnArrayTranslate(1, tm, this._defList.getKeyFieldDataTypes(), dataTypes);
- view.setHyperlinkField(this._defList.getHyperlinkField());
- }
-
- public void loadView() {
- WizardManager wm = ((WizardModelAbstract)this).getWizardManager();
- this._defList = wm.getDefList(this);
- WizardViewDbList3 view = (WizardViewDbList3)((WizardPage)this).getView();
- view.setDataType(this.getDataTypes());
- view.setHLFieldList(this.getListFields());
- view.setLinkOption(this._linkOption);
- DefaultListModel lm = (DefaultListModel)view.getFieldList().getModel();
- DefQuery defQuery = this.getDefQuery();
- if (defQuery != null) {
- lm.setSize(0);
-
- try {
- WizDbManager.getFields(defQuery, false, lm);
- } catch (EWizDbManager e) {
- AspWizardExceptionHandler.showMessage(0, ((Throwable)e).getMessage());
- }
- }
-
- this.loadValues();
- DefaultTableModel tm = (DefaultTableModel)view.getFieldSpecTable().getModel();
- UiUtil.validateTableAgainstList(tm, lm, 0);
- }
-
- public void validate() throws InternalError, ExternalError {
- super.validate();
- WizardViewDbList3 view = (WizardViewDbList3)((WizardPage)this).getView();
- DefaultTableModel KFCollection = view.getKeyFields();
- if (KFCollection.getRowCount() > 10) {
- String msg = ResourceUtil.getResourceString("asp.wizard.res", class$asp$wizard$WVPanelDbListLink != null ? class$asp$wizard$WVPanelDbListLink : (class$asp$wizard$WVPanelDbListLink = class$("asp.wizard.WVPanelDbListLink")), "msg.error.toomanykeyfields");
- Object[] args = new Object[]{new Integer(10)};
- msg = MessageFormat.format(msg, args);
- throw new EWizardModelExt(msg);
- } else {
- for(int i = 0; i < KFCollection.getRowCount(); ++i) {
- if (KFCollection.getValueAt(i, 0).toString().length() == 0 || KFCollection.getValueAt(i, 1).toString().length() == 0) {
- String err = ResourceUtil.getResourceString("asp.wizard.res", class$asp$wizard$WVPanelDbListLink != null ? class$asp$wizard$WVPanelDbListLink : (class$asp$wizard$WVPanelDbListLink = class$("asp.wizard.WVPanelDbListLink")), "msg.error.missingvalueonline");
- Object[] args = new Object[]{new Integer(i + 1)};
- String str = MessageFormat.format(err, args);
- throw new ExternalError(str);
- }
- }
-
- }
- }
-
- private DefQuery getDefQuery() {
- DefQuery result = null;
- WizardManager wm = ((WizardModelAbstract)this).getWizardManager();
- if (wm != null) {
- result = wm.getDefQuery(this);
- } else {
- System.err.println("WizardManager not found");
- }
-
- return result;
- }
-
- public Vector getDataTypes() {
- String test = ResourceUtil.getResourceString("asp.nfx.res", class$asp$nfx$MSDBList$MSDBList != null ? class$asp$nfx$MSDBList$MSDBList : (class$asp$nfx$MSDBList$MSDBList = class$("asp.nfx.MSDBList.MSDBList")), "option.kfldtype");
- Vector result = UiUtil.strToVector(test);
- return result;
- }
-
- protected String getQueryDataType(String fieldName) {
- String result = "";
- ResultSet rs = null;
- DefQuery defQuery = this.getDefQuery();
- if (defQuery != null) {
- int DBType = -1;
-
- try {
- DBType = WizDbManager.getDBTypes(defQuery, fieldName);
- } catch (EWizDbManager e) {
- AspWizardExceptionHandler.showMessage(0, ((Throwable)e).getMessage());
- }
-
- String reserveWord = WizDbManager.getDataTypeName(DBType);
- Vector internalDataTypes = WizDbManager.getInternalDataTypes();
- Vector dataTypes = this.getDataTypes();
- result = dataTypes.elementAt(internalDataTypes.indexOf(reserveWord)).toString();
- }
-
- return result;
- }
-
- protected String[] getListFields() {
- WizardManager wm = ((WizardModelAbstract)this).getWizardManager();
- DefList result = wm.getDefList(this);
- return result.getFieldNames();
- }
-
- public static void setTableModelFromColumnArrayTranslate(int colIndex, DefaultTableModel tableModel, int[] array, Vector lkpVector) {
- if (tableModel != null && array != null) {
- int colCount = tableModel.getColumnCount();
- if (colIndex >= 0 && colIndex < colCount) {
- int rowCount = Array.getLength(array);
- tableModel.setNumRows(rowCount);
-
- for(int r = 0; r < rowCount; ++r) {
- tableModel.setValueAt(lkpVector.elementAt(array[r]), r, colIndex);
- }
- }
- }
-
- }
-
- public static int[] getColumnArrayFromTableModelTranslate(int colIndex, TableModel tableModel, Class columnClass, Vector lkpVector) {
- int[] result = null;
- if (columnClass == null) {
- columnClass = class$java$lang$Object != null ? class$java$lang$Object : (class$java$lang$Object = class$("java.lang.Object"));
- }
-
- if (tableModel != null && colIndex >= 0 && colIndex < tableModel.getColumnCount()) {
- int rowCount = tableModel.getRowCount();
- if (rowCount > 0) {
- int[] aColumn = null;
-
- try {
- aColumn = (int[])Array.newInstance(columnClass, rowCount);
- } catch (Exception e) {
- System.err.println("getColumnArrayFromTableModelTranslate(): " + ((Throwable)e).getMessage());
- }
-
- if (aColumn != null) {
- for(int r = 0; r < rowCount; ++r) {
- aColumn[r] = lkpVector.indexOf(tableModel.getValueAt(r, colIndex));
- }
-
- result = aColumn;
- }
- }
- }
-
- return result;
- }
-
- public WizardModelDbList3() {
- }
-
- public WizardModelDbList3(Wizard wizard, String bullet, String info, ImageIcon icon, ExceptionHandler handler) {
- super(wizard, bullet, info, icon, handler);
- }
-
- protected WizardPageView getViewSingleInstance() {
- return WizardViewDbList3.getInstance();
- }
-
- public WizardPage getNext(int nextSeqTemplateId) throws InternalError, ExternalError {
- WizardPage next = super.getNext();
- WizardManager wm = ((WizardModelAbstract)this).getWizardManager();
- DefPage nextDefPage = null;
- if (next != null && ((WizardModelAbstract)next).getTemplateId() != nextSeqTemplateId) {
- nextDefPage = ((WizardModelAbstract)next).getDefPage();
- next = wm.getSequenceHead(next);
- wm.removeSequence(next);
- next = null;
- DefPage var12 = null;
- } else if (next != null) {
- WizardModelAbstract nextModel = (WizardModelAbstract)next;
- if (nextModel.getTemplateId() == 1 || nextModel.getTemplateId() == 0) {
- DefConnection currDefConn = wm.getDefConnection(this);
- DefConnection nextDefConn = wm.getDefConnection(nextModel);
- if (currDefConn != null && !currDefConn.equalConnectionTo(nextDefConn)) {
- nextDefConn.setEqualConnectionTo(currDefConn);
- }
-
- DefQuery nextDefQuery = wm.getDefQuery(nextModel);
- if (nextDefQuery != null && nextDefQuery.getUsePreviousQuery() == 0) {
- DefQuery currDefQuery = wm.getDefQuery(this);
- if (!currDefQuery.equalSqlStatementTo(nextDefQuery)) {
- nextDefQuery.setEqualSqlStatementTo(currDefQuery);
- this.setupResultSetFor(nextDefQuery);
- }
- }
- }
- }
-
- if (next == null) {
- if (nextSeqTemplateId != 2) {
- nextDefPage = wm.createDefPage(this, nextSeqTemplateId);
- ((WizardModelAbstract)this).getDefPage().addChildPage(nextDefPage);
- wm.addSequence(this, this, nextDefPage, nextSeqTemplateId, (DefPage)null);
- this.setupConnectionAndQueryModels(nextDefPage, nextSeqTemplateId);
- wm.updateNextDefPageId(this, nextSeqTemplateId);
- } else {
- wm.addSequence(this, this, (DefPage)null, nextSeqTemplateId, (DefPage)null);
- }
-
- next = super.getNext();
- }
-
- return next;
- }
-
- public WizardPage getNext() throws InternalError, ExternalError {
- int nextSeqTemplateId = this.getSeqTemplateId();
- return this.getNext(nextSeqTemplateId);
- }
-
- public int getSeqTemplateId() {
- WizardViewDbList3 wv = (WizardViewDbList3)((WizardPage)this).getView();
- return wv.getSeqTemplateId();
- }
-
- private void setupResultSetFor(DefQuery aDefQuery) throws InternalError {
- try {
- WizDbManager wdbm = WizDbManager.getInstance();
- DefConnection defConnection = aDefQuery.getDefConnection();
- Connection conn = wdbm.getConnection(defConnection.getDSNName(), defConnection.getUserName(), defConnection.getPassword());
- ResultSet rs = wdbm.getResultSet(conn, aDefQuery.getSql());
- aDefQuery.setResultSet(rs);
- } catch (EWizDbManager e) {
- throw new InternalError(((Throwable)e).getMessage());
- }
- }
-
- private void setupConnectionAndQueryModels(DefPage newDefPage, int nextSeqTemplateId) throws ExternalError, InternalError {
- if (nextSeqTemplateId == 0 || nextSeqTemplateId == 1) {
- WizardManager wizman = ((WizardModelAbstract)this).getWizardManager();
- WizardModelAbstract model = null;
- boolean needSetupNewQuery = nextSeqTemplateId == 1;
- DefConnection defConnection = wizman.getDefConnection(this);
- DefConnection newDefConnection = new DefConnection(defConnection);
- ((DefAbstract)newDefConnection).setName(((DefCollection)newDefPage).getUniqueNameFor(newDefConnection));
- ((DefCollection)newDefPage).addElement(newDefConnection);
- DefQuery defQuery = null;
- DefQuery newDefQuery = null;
- if (needSetupNewQuery) {
- defQuery = wizman.getDefQuery(this);
- newDefQuery = new DefQuery(defQuery);
- ((DefAbstract)newDefQuery).setName(((DefCollection)newDefPage).getUniqueNameFor(newDefQuery));
- newDefQuery.setDefConnection(newDefConnection);
- newDefQuery.setUsePreviousQuery(1);
- this.setupResultSetFor(newDefQuery);
- ((DefCollection)newDefPage).addElement(newDefQuery);
- ((DefAbstract)newDefPage).setDefQuery(newDefQuery);
- }
-
- switch (nextSeqTemplateId) {
- case 0:
- model = (WizardModelAbstract)wizman.getModelOfClassRightOf(class$asp$wizard$WizardModelDbConnection != null ? class$asp$wizard$WizardModelDbConnection : (class$asp$wizard$WizardModelDbConnection = class$("asp.wizard.WizardModelDbConnection")), this);
- model.setSkip(true);
- ((WizardModelDbConnection)model).setDefConnection(newDefConnection);
- model = (WizardModelAbstract)wizman.getModelOfClassRightOf(class$asp$wizard$WizardModelDbQuery != null ? class$asp$wizard$WizardModelDbQuery : (class$asp$wizard$WizardModelDbQuery = class$("asp.wizard.WizardModelDbQuery")), this);
- break;
- case 1:
- model = (WizardModelAbstract)wizman.getModelOfClassRightOf(class$asp$wizard$WizardModelDbConnection != null ? class$asp$wizard$WizardModelDbConnection : (class$asp$wizard$WizardModelDbConnection = class$("asp.wizard.WizardModelDbConnection")), this);
- model.setSkip(true);
- ((WizardModelDbConnection)model).setDefConnection(newDefConnection);
- model = (WizardModelAbstract)wizman.getModelOfClassRightOf(class$asp$wizard$WizardModelDbQuery != null ? class$asp$wizard$WizardModelDbQuery : (class$asp$wizard$WizardModelDbQuery = class$("asp.wizard.WizardModelDbQuery")), this);
- WizDbManager wdbm = WizDbManager.getInstance();
- newDefQuery.setUsePreviousQuery(0);
- model.setSkip(true);
- ((WizardModelDbQuery)model).setDefQuery(newDefQuery);
- model = (WizardModelAbstract)wizman.getModelOfClassRightOf(class$asp$wizard$WizardModelDbDetail != null ? class$asp$wizard$WizardModelDbDetail : (class$asp$wizard$WizardModelDbDetail = class$("asp.wizard.WizardModelDbDetail")), this);
- if (model != null) {
- ((WizardModelDbDetail)model).setShowQuery(true);
- }
- }
-
- }
- }
-
- // $FF: synthetic method
- static Class class$(String class$) {
- try {
- return Class.forName(class$);
- } catch (ClassNotFoundException forName) {
- throw new NoClassDefFoundError(((Throwable)forName).getMessage());
- }
- }
- }
-